
// A6_match_data
//==============================================================================

// Description: This code matches the data on the number of companies to the data
// set, so that it can more easily be read-in during the supply-side inference

clear
set more off

cd "D:\data_replication"


// Match demand estimation data to companies
//==============================================================================

forval j = 1/4092 {

import delimited estimation\4_demand_estimation\3_baseline\data_`j'.csv, clear 

gen k = `j'
keep k declarant market_id

merge m:1 k declarant using data\number_firms\companies_k.dta
drop if _merge == 2
drop _merge

egen companies_avg = mean(companies_k)
replace companies_k = companies_avg if companies_k == .

sort market_id

export delimited using data\number_firms\product_files\companies_data_`j'.csv, replace

}

